import request from "@/http/index.ts"

// 数据配置 VO
export interface SpecificationConfigurationVO {
  id: number // id
  defaultValue: string // 
  judgmentConditions: string // 
  materialName: string // 状态
  materialSpecifications: string // 文本
  pid: any // 父ID
  height: any // 
  heightJudgment: any // 
  number: any // 
  numberJudgment: any // 
  width: any // 
  widthJudgment: any // 
}

// 查询参数接口
export interface SearchParams {
  materialName?: string;
  materialSpecifications?: string;
}

// 数据配置 API
export const SpecificationConfigurationApi = {
  // 查询数据配置列表
  getlistTree: async (params?: SearchParams) => {
    let url = `specificationConfiguration/listTree`;
    if (params) {
      const queryParams = new URLSearchParams();
      if (params.materialName) {
        queryParams.append('materialName', params.materialName);
      }
      if (params.materialSpecifications) {
        queryParams.append('materialSpecifications', params.materialSpecifications);
      }
      
      const queryString = queryParams.toString();
      if (queryString) {
        url += `?${queryString}`;
      }
    }
    return await request.get(url);
  },
  // 查询上级菜单
  getParent: async () => {
    return await request.get(`/specificationConfiguration/getParent`)
  },
  // 新增数据配置
  create: async (data: SpecificationConfigurationVO) => {
    return await request.post(`/specificationConfiguration/create`, data)
  },

  // 修改数据配置
  update: async (data: SpecificationConfigurationVO) => {
    return await request.put(`/specificationConfiguration/update`, data)
  },

  // 删除数据配置
  delete: async (id: number) => {
    return await request.delete(`/specificationConfiguration/delete/` + id)
  },
}
